import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import static java.lang.System.out;

// To Remove: all cases where a color starts a search at a board where the opponent is to move
// i.e. all tests for 'losing' & some random board tests
// these situations should never occur (a player only starts a search when it's her turn)

public class TestQABMiniMax extends TestCase {
    private static final Class thisClass = TestQABMiniMax.class;

    final int MAX = ComputerPlayer.WHITE_WIN;
    final int MIN = ComputerPlayer.WHITE_LOSS;

    public static void main(String[] args) {
        if (args.length >= 1 && args[0].equals("text")) {
            junit.textui.TestRunner.run(thisClass);
        } else {
            junit.swingui.TestRunner.run(thisClass);
        }
    }

    public static Test suite() {
        return new TestSuite(thisClass);
    }

    public void testWinning1() {
	
	// Case: white takes the last black & is crowned within one move
	Board board = Board.parseWdp(".... .b.. .w.. .... .... .... .... .... w");

	QABMiniMax p = new QABMiniMax(board.blackToMove,new EvalMaterialOnly(),1);
	int bestValue = p.search(board, 1, MIN, MAX);
	
	assertEquals(MAX, bestValue);
    }

    public void testWinning2() {

	// Case: white blocks the last black within one move
	Board board = Board.parseWdp(".... .... ...b .... ..ww .... .... .... w");

	QABMiniMax p = new QABMiniMax(board.blackToMove,new EvalMaterialOnly(),1);
	int bestValue = p.search(board, 1, MIN, MAX);
	
	assertEquals(MAX, bestValue);
    }

    public void testEvalCrown() {
	// Case: white is crowned within one move
	Board board = Board.parseWdp(".... .w.. .... .... .b.. .... .... .... w");

	QABMiniMax p = new QABMiniMax(board.blackToMove,new EvalMaterialOnly(),1);
	int bestValue = p.search(board, 1, MIN, MAX);
	
	assertEquals(Eval.KINGS, bestValue);
    }

    public void testEvalCapture() {
	// Case: starting with same number of players (eval==0)
	//       white captures one black within one move

	Board board = Board.parseWdp("...b .... .b.. ..w. .... .... .... .w.. w");

	QABMiniMax p = new QABMiniMax(board.blackToMove,new EvalMaterialOnly(),1);
	int bestValue = p.search(board, 1, MIN, MAX);
	
	assertEquals(Eval.MEN, bestValue);
    }

    public void test2stepCapture() {
    }

    
    public void testAgainstAlphaBeta() {

	/* TODO: Set up a game between Quiescence AB and ordinary AB, 
	   check that Quiescence AB wins..? */	

	// Q plays black
	QABMiniMax q = new QABMiniMax(true,new EvalMaterialOnly(),12);
	ABMiniMax p = new ABMiniMax(false,new EvalMaterialOnly(),5);
	GameEngine.runGame(q, p, new Board());

    }
}
